package service

import (
	"encoding/json"
)

var checkMenuArr = map[string]int{
	"AdminUserControllerIndex":1,
	"AdminUserControllerAjaxAdd":1,
	"AdminUserControllerAjaxEdit":1,
	"AdminUserControllerAjaxDelete":1,
	"RoleControllerIndex" : 1,
	"RoleControllerAjaxAdd":1,
	"RoleControllerAjaxEdit":1,
	"RoleControllerAjaxDelete":1,
	"UploadImageControllerIndex" : 1,
	"UploadImageControllerAjaxUploadImage" : 1,
	"UploadImageControllerAjaxImageDelete" : 1,
	"MenuControllerMenuList" : 1,
	"CarouselControllerIndex" : 1,
	"CarouselControllerAjaxAddCarousel" : 1,
	"CarouselControllerAjaxEditCarousel" : 1,
	"CarouselControllerAjaxDeleteCarousel" : 1,
	"ArticleControllerIndex" : 1,
	"ArticleControllerAjaxAddArticle" : 1,
	"ArticleControllerAjaxEditArticle" : 1,
	"ArticleControllerAjaxDeleteArticle" : 1,
	"ArticleCatControllerIndex" : 1,
	"ArticleCatControllerAjaxAddArticleCat" : 1,
	"ArticleCatControllerAjaxEditArticleCat" : 1,
	"ArticleCatControllerAjaxDeleteArticleCat" : 1,
	"ArticleTagsControllerIndex" : 1,
	"ArticleTagsControllerAjaxAddArticleTags" : 1,
	"ArticleTagsControllerAjaxEditArticleTags" : 1,
	"ArticleTagsControllerAjaxDeleteArticleTags" : 1,
}
func CheckMenuAuth(controllerName string,actionName string,authControllerJson string,roleId int) bool{
	controllerActionName := controllerName + actionName
	if _, ok :=checkMenuArr[controllerActionName]; ok && roleId != 1{
		JsonRes := make(map[string]int)
		_ = json.Unmarshal([]byte(authControllerJson), &JsonRes)
		if _, ok :=JsonRes[controllerActionName]; !ok{
			return false
		}
	}

	return true
}
